package com.easy;

/**
 * Created by Lxk on 2019/6/2.
 */
public class Solution203 {

    public ListNode removeElements(ListNode head, int val) {
        if(head==null){
            return null;
        }
        while(head!=null && head.val==val){
            head = head.next;
        }
        ListNode pre = head,cur = head!=null ? head.next : null;
        while(cur!=null){
            if(cur.val==val){
                pre.next = cur.next;
                cur.next = null;
                cur = pre.next;
            }else{
                cur = cur.next;
                pre = pre.next;
            }
        }
        return head;
    }

}
